package com.leoman.resources.dao;

import com.leoman.common.dao.IBaseJpaRepository;
import com.leoman.resources.entity.ResourceData;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * resourceDataDao
 * Created by 涂奕恒 on 2016/12/14.
 */
public interface ResourceDataDao extends IBaseJpaRepository<ResourceData> {

    @Query("select a from ResourceData a where a.resourceId = ?1 and a.type = ?2 and a.createDate = ?3")
    ResourceData findOneByParams(Long resourceId, Integer type, String startDate);

    @Query("select a from ResourceData a where a.resourceId = ?1 and a.type = ?2 and a.createDate >= ?3 and a.createDate <= ?4")
    List<ResourceData> findListByParams(Long resourceId, Integer type, String startDate, String endDate);

    @Query("select a from ResourceData a where a.type = ?1 and a.resourceId = ?2")
    Page<ResourceData> pageByTypeAndResourceId(Integer type, Long resourceId, Pageable pageable);

    @Query("select a from ResourceData a where a.type = ?1 and a.createDate >= ?2 and a.createDate <= ?3 group by a.resourceId")
    Page<ResourceData> pageByTypeAndCreateDate(Integer type, String startDate, String endDate, Pageable pageable);

    @Query("select a from ResourceData a where a.type = ?1 and a.resourceName like ?2 and a.createDate >= ?3 and a.createDate <= ?4 group by a.resourceId")
    Page<ResourceData> pageByTypeAndNameAndCreateDate(Integer type, String resourceName, String startDate, String endDate, Pageable pageable);

    @Query("select a from ResourceData a where a.type = ?1 and a.resourceId = ?2")
    List<ResourceData> findListByTypeAndResourceId(Integer type, Long resourceId);

    @Query("select a from ResourceData a where a.type = ?1")
    List<ResourceData> findListByType(Integer type);
}
